package app.qrcode.browser.todoapp.data.repository

import androidx.lifecycle.LiveData
import app.qrcode.browser.todoapp.data.ToDoDao
import app.qrcode.browser.todoapp.data.models.TaskStatus
import app.qrcode.browser.todoapp.data.models.ToDoData

/**
 * Created by YiGo on 2022/5/6.
 */
class ToDoRepository(private val toDoDao: ToDoDao) {
    val getAllData: LiveData<List<ToDoData>> = toDoDao.getAllData()

    val sortByHighPriority: LiveData<List<ToDoData>> = toDoDao.sortByHighPriority()
    val sortByLowPriority: LiveData<List<ToDoData>> = toDoDao.sortByLowPriority()

    val sortByHighTaskStatus: LiveData<List<ToDoData>> = toDoDao.sortByHighTaskStatus()
    val sortByLowTaskStatus: LiveData<List<ToDoData>> = toDoDao.sortByLowTaskStatus()

    val classifiedIntoHighPriority: LiveData<List<ToDoData>> = toDoDao.classifiedIntoHighPriority()
    val classifiedIntoMediumPriority: LiveData<List<ToDoData>> =
        toDoDao.classifiedIntoMediumPriority()
    val classifiedIntoLowPriority: LiveData<List<ToDoData>> = toDoDao.classifiedIntoLowPriority()
    val classifiedIntoHighTaskStatus: LiveData<List<ToDoData>> =
        toDoDao.classfiedIntoHighTaskStatus()
    val classifiedIntoMediumTaskStatus: LiveData<List<ToDoData>> =
        toDoDao.classfiedIntoMediumTaskStatus()
    val classifiedIntoLowTaskStatus: LiveData<List<ToDoData>> = toDoDao.classfiedIntoLowTaskStatus()

//    val chooseIsNoticedItem:List<ToDoData> = toDoDao.chooseIsNoticedItem()

    suspend fun insertData(toDoData: ToDoData) {
        toDoDao.insertData(toDoData)
    }

    suspend fun updateData(toDoData: ToDoData) {
        toDoDao.updateData(toDoData)
    }

    suspend fun updateTaskStatus(id: Int, taskStatus: TaskStatus) {
        toDoDao.updateTaskStatus(id, taskStatus)
    }

    suspend fun deleteItem(toDoData: ToDoData) {
        toDoDao.deleteItem(toDoData)
    }

    suspend fun deleteAll() {
        toDoDao.deleteAll()
    }

    fun searchDatabase(searchQuery: String): LiveData<List<ToDoData>> {
        return toDoDao.searchDataBase(searchQuery)
    }



}